package cz.mff.cuni.dpp.liboptions;

import java.text.MessageFormat;

@SuppressWarnings("serial")
class BadValueException extends Exception {

	private static final String MESSAGE_PATTERN = "{0} is not acceptable value for option {1}, is out of range: {2}";

	private final String stringValue;
	private final Option<?> option;
	private final boolean outOfRange;

	public BadValueException(String stringValue, Option<?> option, boolean outOfRange) {
		super(MessageFormat.format(MESSAGE_PATTERN, stringValue, option.getPrimaryName(),
				outOfRange));
		this.option = option;
		this.stringValue = stringValue;
		this.outOfRange = outOfRange;
	}

	/**
	 * Pokud neni out of range. Vola
	 * {@link #BadValueException(String, Option, boolean)} s poslednim
	 * parametrem outOfRange = false.
	 * 
	 * @param stringValue
	 * @param option
	 */
	public BadValueException(String stringValue, Option<?> option) {
		this(stringValue, option, false);
	}

	public String getStringValue() {
		return stringValue;
	}

	public Option<?> getOption() {
		return option;
	}

	public boolean isOutOfRange() {
		return outOfRange;
	}

}
